package com.itkjb.leisurely.center.oauth.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Copyright (C), 2018-2099
 * FileName: Oauth2Controller
 *
 * @Author: lix
 * @Date: 2019-06-19 16:28
 * @Description: 认证controller
 * @Version: V1.0.0
 */

@RestController
@SessionAttributes("authorizationRequest")
public class Oauth2Controller {

    @Autowired
    private ClientDetailsService clientDetailsService;
    @RequestMapping("/oauth/confirm_access")
    public ModelAndView getAccessConfirmation(Map<String, Object> model, HttpServletRequest request) throws Exception {
        AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");
        ModelAndView view = new ModelAndView();
        view.setViewName("base-grant");


        ClientDetails clientDetails = clientDetailsService.loadClientByClientId(authorizationRequest.getClientId());


        view.addObject("scope",clientDetails.getScope());
        view.addObject("clientId", authorizationRequest.getClientId());
        return view;
    }

}
